package com.huazai.apply.manager.service.impl;


import com.huazai.apply.manager.bean.User;
import com.huazai.apply.manager.dao.impl.UserDaoImpl;
import com.huazai.apply.manager.service.UserInitService;

/**
 * @author EZTTU
 */
public class UserInitServiceImpl implements UserInitService {
    private final UserDaoImpl userDao = new UserDaoImpl();

    @Override
    public String doRegister(User user) {
        String userId = user.getUserId();
        String userField = user.getUserField();
        String userName = user.getUserName();
        String userPassword = user.getUserPassword();

        String mes = null;

        if (userDao.checkUsername(userId, userField)) {
            mes = "该用ID已经注册过了。。。";
            return mes;
        } else if (userDao.signup(userName, userId, userPassword, userField)) {
            mes = "注册成功，快回去登录吧 ~~~";
        } else {
            mes = "注册失败了。。。请重试 ";
        }
        return mes;
    }

    @Override
    public String doLogin(User user) {
        String userId = user.getUserId();
        String userField = user.getUserField();
        String userPassword = user.getUserPassword();

        String mes;

        if (!userDao.checkUsername(userId, userField)) {
            mes = "登录失败，用户不存在";
            return mes;
        }
        if (userDao.login(userId, userPassword, userField)) {
            mes = "登录成功";
            return mes;
        }

        mes = "登录失败，密码错误";
        return mes;
    }
}
